﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KLADR;

namespace SampleUsage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void selectFileButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string fName = openFileDialog1.FileName;
                fileNameTextBox.Text = fName.Substring(0,fName.LastIndexOf('\\'));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            KLADR.ImportKladr imp = new KLADR.ImportKladr();
            imp.SqlConnectionString = Properties.Settings.Default.kladrDB;
            imp.DbConnectionString = string.Format("Provider=VFPOLEDB.1;Data Source={0}",fileNameTextBox.Text);
            imp.import();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = kladrEdit1.Address;
        }

        private void kladrEdit1_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            textBox1.Text = kladrEdit1.Address;
        }
    }
}
